var DataTypes = require('sequelize').DataTypes;
var _sys_permission = require('./sys_permission');
var _sys_role = require('./sys_role');
var _sys_role_permission = require('./sys_role_permission');
var _sys_user = require('./sys_user');
var _sys_user_role = require('./sys_user_role');
var _t_attendance = require('./t_attendance');
var _t_contract = require('./t_contract');
var _t_dept = require('./t_dept');
var _t_dict_item = require('./t_dict_item');
var _t_dict_type = require('./t_dict_type');
var _t_employee = require('./t_employee');
var _t_employee_transfer = require('./t_employee_transfer');
var _t_employee_work = require('./t_employee_work');
var _t_employment_type = require('./t_employment_type');
var _t_leave = require('./t_leave');
var _t_performance = require('./t_performance');
var _t_position = require('./t_position');
var _t_salary = require('./t_salary');
var _t_social_security = require('./t_social_security');
var _t_training = require('./t_training');
var _t_training_record = require('./t_training_record');

function initModels(sequelize) {
    var sys_permission = _sys_permission(sequelize, DataTypes);
    var sys_role = _sys_role(sequelize, DataTypes);
    var sys_role_permission = _sys_role_permission(sequelize, DataTypes);
    var sys_user = _sys_user(sequelize, DataTypes);
    var sys_user_role = _sys_user_role(sequelize, DataTypes);
    var t_attendance = _t_attendance(sequelize, DataTypes);
    var t_contract = _t_contract(sequelize, DataTypes);
    var t_dept = _t_dept(sequelize, DataTypes);
    var t_dict_item = _t_dict_item(sequelize, DataTypes);
    var t_dict_type = _t_dict_type(sequelize, DataTypes);
    var t_employee = _t_employee(sequelize, DataTypes);
    var t_employee_transfer = _t_employee_transfer(sequelize, DataTypes);
    var t_employee_work = _t_employee_work(sequelize, DataTypes);
    var t_employment_type = _t_employment_type(sequelize, DataTypes);
    var t_leave = _t_leave(sequelize, DataTypes);
    var t_performance = _t_performance(sequelize, DataTypes);
    var t_position = _t_position(sequelize, DataTypes);
    var t_salary = _t_salary(sequelize, DataTypes);
    var t_social_security = _t_social_security(sequelize, DataTypes);
    var t_training = _t_training(sequelize, DataTypes);
    var t_training_record = _t_training_record(sequelize, DataTypes);

    sys_permission.belongsTo(sys_permission, { as: 'parent', foreignKey: 'parent_id' });
    sys_permission.hasMany(sys_permission, { as: 'sys_permissions', foreignKey: 'parent_id' });
    sys_role_permission.belongsTo(sys_permission, { as: 'perm', foreignKey: 'perm_id' });
    sys_permission.hasMany(sys_role_permission, { as: 'sys_role_permissions', foreignKey: 'perm_id' });
    sys_role_permission.belongsTo(sys_role, { as: 'role', foreignKey: 'role_id' });
    sys_role.hasMany(sys_role_permission, { as: 'sys_role_permissions', foreignKey: 'role_id' });
    sys_user_role.belongsTo(sys_role, { as: 'role', foreignKey: 'role_id' });
    sys_role.hasMany(sys_user_role, { as: 'sys_user_roles', foreignKey: 'role_id' });
    sys_user_role.belongsTo(sys_user, { as: 'user', foreignKey: 'user_id' });
    sys_user.hasMany(sys_user_role, { as: 'sys_user_roles', foreignKey: 'user_id' });
    t_dept.belongsTo(t_dept, { as: 'parent', foreignKey: 'parent_id' });
    t_dept.hasMany(t_dept, { as: 't_depts', foreignKey: 'parent_id' });
    t_employee.belongsTo(t_dept, { as: 'dept', foreignKey: 'dept_id' });
    t_dept.hasMany(t_employee, { as: 't_employees', foreignKey: 'dept_id' });
    t_position.belongsTo(t_dept, { as: 'dept', foreignKey: 'dept_id' });
    t_dept.hasMany(t_position, { as: 't_positions', foreignKey: 'dept_id' });
    t_dict_item.belongsTo(t_dict_type, { as: 'dict_type', foreignKey: 'dict_type_id' });
    t_dict_type.hasMany(t_dict_item, { as: 't_dict_items', foreignKey: 'dict_type_id' });
    t_attendance.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_attendance, { as: 't_attendances', foreignKey: 'emp_id' });
    t_contract.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_contract, { as: 't_contracts', foreignKey: 'emp_id' });
    t_dept.belongsTo(t_employee, { as: 'manager', foreignKey: 'manager_id' });
    t_employee.hasMany(t_dept, { as: 't_depts', foreignKey: 'manager_id' });
    t_employee.belongsTo(t_employee, { as: 'manager', foreignKey: 'manager_id' });
    t_employee.hasMany(t_employee, { as: 't_employees', foreignKey: 'manager_id' });
    t_employee_transfer.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_employee_transfer, { as: 't_employee_transfers', foreignKey: 'emp_id' });
    t_employee_transfer.belongsTo(t_employee, { as: 'operator', foreignKey: 'operator_id' });
    t_employee.hasMany(t_employee_transfer, { as: 'operator_t_employee_transfers', foreignKey: 'operator_id' });
    t_employee_work.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_employee_work, { as: 't_employee_works', foreignKey: 'emp_id' });
    t_leave.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_leave, { as: 't_leaves', foreignKey: 'emp_id' });
    t_leave.belongsTo(t_employee, { as: 'approver', foreignKey: 'approver_id' });
    t_employee.hasMany(t_leave, { as: 'approver_t_leaves', foreignKey: 'approver_id' });
    t_performance.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_performance, { as: 't_performances', foreignKey: 'emp_id' });
    t_performance.belongsTo(t_employee, { as: 'evaluator', foreignKey: 'evaluator_id' });
    t_employee.hasMany(t_performance, { as: 'evaluator_t_performances', foreignKey: 'evaluator_id' });
    t_salary.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_salary, { as: 't_salaries', foreignKey: 'emp_id' });
    t_social_security.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_social_security, { as: 't_social_securities', foreignKey: 'emp_id' });
    t_training_record.belongsTo(t_employee, { as: 'emp', foreignKey: 'emp_id' });
    t_employee.hasMany(t_training_record, { as: 't_training_records', foreignKey: 'emp_id' });
    t_employee.belongsTo(t_employment_type, { as: 'employment_type', foreignKey: 'employment_type_id' });
    t_employment_type.hasMany(t_employee, { as: 't_employees', foreignKey: 'employment_type_id' });
    t_employee.belongsTo(t_position, { as: 'position', foreignKey: 'position_id' });
    t_position.hasMany(t_employee, { as: 't_employees', foreignKey: 'position_id' });
    t_training_record.belongsTo(t_training, { as: 'training', foreignKey: 'training_id' });
    t_training.hasMany(t_training_record, { as: 't_training_records', foreignKey: 'training_id' });

    return {
        sys_permission,
        sys_role,
        sys_role_permission,
        sys_user,
        sys_user_role,
        t_attendance,
        t_contract,
        t_dept,
        t_dict_item,
        t_dict_type,
        t_employee,
        t_employee_transfer,
        t_employee_work,
        t_employment_type,
        t_leave,
        t_performance,
        t_position,
        t_salary,
        t_social_security,
        t_training,
        t_training_record,
    };
}
module.exports = initModels;
module.exports.initModels = initModels;
module.exports.default = initModels;
